<form id="form-changePwd" onsubmit="return false;">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<div class="dashedBorder">
	<table class="am-table am-table-striped am-form">
		<tr>
			<td style="width: 15%">原始密码：</td>
			<td><input type="password" name="oldPwd"> </td>
		</tr>
		<tr>
			<td>新密码：</td>
			<td><input type="password" name="newPwd"></td>
		</tr>
		<tr>
			<td>重复密码：</td>
			<td><input type="password" name="rptPwd"></td>
		</tr>
	</table>
	<div id="float-captcha" style="margin-bottom:20px"></div>
	<button class="am-btn am-btn-lg am-btn-primary" id="btn-changePwd">提交</button>
</div>
</form>
<div>
	<table class="am-table am-table-striped am-form">
		<tr data="duoshuo_id">
			<td style="width: 15%">多说ID：</td>
			<td style="width: 70%"><input type="text" name="duoshuoId"></td>
			<td style="width: 15%"><button class="am-btn am-btn-primary am-btn-sm btn-updateOthers"><i class="am-icon-fw am-icon-save"></i></button></td>
		</tr>
		<tr data="qiniu_access_key">
			<td>七牛公钥KEY：</td>
			<td><input type="text" name="qiniuAK"></td>
			<td><button class="am-btn am-btn-primary am-btn-sm btn-updateOthers"><i class="am-icon-fw am-icon-save"></i></button></td>
		</tr>
		<tr data="qiniu_secret_key">
			<td>七牛密钥KEY：</td>
			<td><input type="text" name="qiniuSK"></td>
			<td><button class="am-btn am-btn-primary am-btn-sm btn-updateOthers"><i class="am-icon-fw am-icon-save"></i></button></td>
		</tr>
		<tr data="geetest_ak">
			<td>Geetest极验公钥KEY：</td>
			<td><input type="text" name="qiniuAK"></td>
			<td><button class="am-btn am-btn-primary am-btn-sm btn-updateOthers"><i class="am-icon-fw am-icon-save"></i></button></td>
		</tr>
		<tr data="geetest_sk">
			<td>Geetest极验密钥KEY：</td>
			<td><input type="text" name="qiniuSK"></td>
			<td><button class="am-btn am-btn-primary am-btn-sm btn-updateOthers"><i class="am-icon-fw am-icon-save"></i></button></td>
		</tr>
	</table>
</div>
<script src="http://static.geetest.com/static/tools/gt.js"></script>
<script type="text/javascript">
	$(function(){
		var captchaObj;

		$.get("${rc.contextPath}/getGeetestStep1Data", function(result){
			initGeetest({
                gt: result.data.gt,
                challenge: result.data.challenge,
            }, handlerFloat);
		},"json");

		var handlerFloat = function (me) {
			// 将验证码加到id为captcha的元素里
			captchaObj = me;
			captchaObj.appendTo("#float-captcha");
		};
	     
		$("#btn-changePwd").bind("click",function(){
			if($(":password[name=newPwd]").val() != $(":password[name=rptPwd]").val()){
				alert("两次输入的新密码不一致，请检查！");
				return;
			}
			if(! captchaObj.getValidate()){
				alert("尚未进行人机验证！");
				return;
			}
			$.ajax({
				url  : "${rc.contextPath}/admin/account/updatePwd",
				data : $("#form-changePwd").serialize(),
				type : "json",
				success : function(result){
					if(result.resultCode == 0){
						alert("修改密码成功！");
					}else{
						alert("修改失败," + result.message);
					}
					captchaObj.refresh();
				},
				error : function(){alert("抱歉，来宾帐户无法对系统做出修改！");captchaObj.refresh();},
				dataType : "json"
			});
		});

		$(".btn-updateOthers").bind("click", function(){
			var tr = $(this).parents("tr");
			var value = tr.find("input").val();
			if(value != undefined && value != ""){
				var key = tr.attr("data");
				$.ajax({
					url : "${rc.contextPath}/admin/account/update",
					data : {"key":key,"value":value,"${_csrf.parameterName}":"${_csrf.token}"},
					type : "post",
					success : function(result){
						if(result.resultCode == 0){
							alert("更新成功！");
						}else{
							alert("更新失败," + result.message);
						}
					},
					error : function(){alert("抱歉，来宾帐户无法对系统做出修改！");},
					dataType : "json"
				});
			}else{
				alert("请输入有效字符！");
			}
		});
	});
</script>